package com.barcamp.manager;

import java.util.List;

import org.springframework.dao.DataAccessException;

import com.barcamp.dao.EventTypeDao;
import com.barcamp.entity.EventType;
import com.exception.PersistenceException;

public class EventTypeManager {
	
	private EventTypeDao etypeDao;
	
	public EventTypeDao getEtypeDao() {
		return etypeDao;
	}
	public void setEtypeDao(EventTypeDao etypeDao) {
		this.etypeDao = etypeDao;
	}
	public void insertNew(EventType type)throws PersistenceException{
		try{
		   etypeDao.insertNew(type);
		}catch(PersistenceException e){
           throw new PersistenceException("Failed to insert.", e);
        }
	}
	  public void updateType(EventType type) throws PersistenceException {
	      try {
	    	  etypeDao.update(type);
	      } catch (DataAccessException e) {
	          throw new PersistenceException("Failed to update.", e);
	      }
	  }
	  public void delete(int id) throws PersistenceException{
	      try {
	    	  etypeDao.delete(id);
	      } catch (DataAccessException e) {
	          throw new PersistenceException("Failed to delete", e);
	      }
	  }
	  public List<EventType> findAllEvent() throws PersistenceException
	  {
	      List<EventType> result = null;
	      try {
	          result = etypeDao.findAll();
	          for(EventType type : result) {
	          }
	      } catch (DataAccessException e) {
	          throw e;}
	      return result;
	  } 
	  public EventType findByID(int id) throws PersistenceException
	  {		EventType result;
	  		try{
	  			result=etypeDao.findByID(id);
	  		}catch(PersistenceException e){
	  			throw new PersistenceException("Failed the process", e);
	  		}
		  return result;
	  }	
}
